import { http } from "@/utils/http";
import { baseAdminURLApi, type PageResult } from "../utils";

export type CategoryVO = {
  id: number;
  name: string;
  createTime: Date;
  updateTime: Date;
};

export interface CategoryDTO {
  id: number;
  name: string;
}
/** 获取分类列表 */
export const getCategoryList = (data?: object) => {
  return http.request<PageResult<CategoryVO>>(
    "get",
    baseAdminURLApi("/category"),
    {
      params: data
    }
  );
};

/** 新增分类 */
export const addCategory = (data?: CategoryDTO) => {
  return http.request<CategoryVO>("post", baseAdminURLApi("/category"), {
    data
  });
};

/** 修改分类 */
export const editCategory = (id: number, data?: CategoryDTO) => {
  return http.request<CategoryVO>("put", baseAdminURLApi(`/category/${id}`), {
    data
  });
};

/** 删除分类 */
export const deleteCategoryList = (data?: Array<number>) => {
  return http.request<CategoryVO>("delete", baseAdminURLApi("/category"), {
    data
  });
};

/** 获取分类字典 */
export const getCategoryDictionary = () => {
  return http.request<Array<CategoryDTO>>(
    "get",
    baseAdminURLApi("/category/options"),
    {}
  );
};
